package com.ruoyi.mail.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaMallRecevingAddress;
import com.ruoyi.system.service.IJiajiaMallRecevingAddressService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城地址簿Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/mall/address")
public class JiajiaMallRecevingAddressController extends BaseController
{
    private String prefix = "mall/address";

    @Autowired
    private IJiajiaMallRecevingAddressService jiajiaMallRecevingAddressService;

    @RequiresPermissions("system:address:view")
    @GetMapping()
    public String address()
    {
        return prefix + "/address";
    }

    /**
     * 查询商城地址簿列表
     */
    @RequiresPermissions("system:address:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaMallRecevingAddress jiajiaMallRecevingAddress)
    {
        startPage();
        List<JiajiaMallRecevingAddress> list = jiajiaMallRecevingAddressService.selectJiajiaMallRecevingAddressList(jiajiaMallRecevingAddress);
        return getDataTable(list);
    }

    /**
     * 导出商城地址簿列表
     */
    @RequiresPermissions("system:address:export")
    @Log(title = "商城地址簿", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaMallRecevingAddress jiajiaMallRecevingAddress)
    {
        List<JiajiaMallRecevingAddress> list = jiajiaMallRecevingAddressService.selectJiajiaMallRecevingAddressList(jiajiaMallRecevingAddress);
        ExcelUtil<JiajiaMallRecevingAddress> util = new ExcelUtil<JiajiaMallRecevingAddress>(JiajiaMallRecevingAddress.class);
        return util.exportExcel(list, "商城地址簿数据");
    }

    /**
     * 新增商城地址簿
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商城地址簿
     */
    @RequiresPermissions("system:address:add")
    @Log(title = "商城地址簿", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaMallRecevingAddress jiajiaMallRecevingAddress)
    {
        return toAjax(jiajiaMallRecevingAddressService.insertJiajiaMallRecevingAddress(jiajiaMallRecevingAddress));
    }

    /**
     * 修改商城地址簿
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaMallRecevingAddress jiajiaMallRecevingAddress = jiajiaMallRecevingAddressService.selectJiajiaMallRecevingAddressById(id);
        mmap.put("jiajiaMallRecevingAddress", jiajiaMallRecevingAddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城地址簿
     */
    @RequiresPermissions("system:address:edit")
    @Log(title = "商城地址簿", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaMallRecevingAddress jiajiaMallRecevingAddress)
    {
        return toAjax(jiajiaMallRecevingAddressService.updateJiajiaMallRecevingAddress(jiajiaMallRecevingAddress));
    }

    /**
     * 删除商城地址簿
     */
    @RequiresPermissions("system:address:remove")
    @Log(title = "商城地址簿", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaMallRecevingAddressService.deleteJiajiaMallRecevingAddressByIds(ids));
    }
}
